﻿using System;
using System.Windows.Media;
using System.Windows.Data;

namespace ReflectionStudio.Controls
{
    /// <summary>
    /// Converter : Enum to string and revert
    /// </summary>
    [ValueConversion(typeof(object), typeof(object))]
    public class RGB2ColorConverter : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                value = "000000000";
            }
            string v = value.ToString();
            object vR = new SolidColorBrush(Colors.White);
            byte cr =System.Convert.ToByte(v.Substring(0,3));
            byte cg = System.Convert.ToByte(v.Substring(3, 3));
            byte cb = System.Convert.ToByte(v.Substring(6, 3));
            vR = Color.FromRgb(cr, cg, cb);             
            return vR;
        }

        /// <summary>
        /// IValueConverter.ConvertBack
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    } 
}
